pauseMenu = {}
--Stores menu selection
local pauseSelection = 0
--hudFontLarge
function pauseMenu:init()
  --Create menu options
  pauseOptions = {}
  pauseOptions[1] = {text = "Resume", x = 640 - hudFontLarge:getWidth("Resume")/2, y = 140, selected = false}
  pauseOptions[2] = {text = "Help", x = 640 - hudFontLarge:getWidth("Help")/2, y = 340, selected = false}
  pauseOptions[3] = {text = "Quit", x = 640 - hudFontLarge:getWidth("Quit")/2, y = 540, selected = false}
  
end

function pauseMenu:enter()
  --Reset selection to "Resume"
  pauseSelection = 0
end

function pauseMenu:update(dt)
  --Which option is selected?
  if pauseSelection == 0 then
    pauseOptions[1].selected = true
    pauseOptions[2].selected = false
    pauseOptions[3].selected = false
  elseif pauseSelection == 1 then
    pauseOptions[1].selected = false
    pauseOptions[2].selected = true
    pauseOptions[3].selected = false
  elseif pauseSelection == 2 then
    pauseOptions[1].selected = false
    pauseOptions[2].selected = false
    pauseOptions[3].selected = true
  end
end

function pauseMenu:draw(dt)
  --Draw a darkened screenshot of the main game
  love.graphics.setColor(255,255,255,64)
  love.graphics.draw(game.screenshot)
  
  --Draw the menu with the appropriate options
  love.graphics.setFont(hudFontLarge)
  for i = 1, #pauseOptions do
    --Set colors for appropriate menu options
    if pauseOptions[i].selected then
      love.graphics.setColor(color.green)
    else
      love.graphics.setColor(color.red)
    end
    --Draw the menu text
    love.graphics.print(pauseOptions[i].text, pauseOptions[i].x, pauseOptions[i].y)
  end
  
  --Draw toggle for audio
  love.graphics.setFont(hudFontSmall)
  love.graphics.setColor(color.red)
  love.graphics.print("[M]ute Audio", 1280-120-hudFontSmall:getWidth("[M]ute Audio"), 720 - 20 - hudFontSmall:getHeight("[M]ute Audio"))

  love.graphics.print("[F]ullscreen", 20 + 120, 720 - 20 - hudFontSmall:getHeight("[F]ullscreen"))
end

function pauseMenu:leave()
end

--Input
function pauseMenu:keypressed(k)
  --Change menu option
  if k == "w" or k == "up" then
    pauseSelection = pauseSelection - 1
  elseif k == "s" or k == "down" then
    pauseSelection = pauseSelection + 1
  end

  --Cycle through menu options
  if pauseSelection > 2 then 
    pauseSelection = 0
  elseif pauseSelection < 0 then
    pauseSelection = 2
  end
  
  --Mute/Unmute audio
  if k == "m" then
    if love.audio.getVolume() ~= 1 then
      love.audio.setVolume(1)
    else
      love.audio.setVolume(0)
    end
  end
  
  --Fullscreen
  if k == 'f' then
    love.graphics.toggleFullscreen()
  end
  
  
  --Return to main game
  if k == "escape" or (k == "return" and pauseSelection == 0) then
    Gamestate.pop(pauseMenu)
  end
  --Help Menu
  if k == "return" and pauseSelection == 1 then
    Gamestate.push(helpMenu)
  end
  if k == "return" and pauseSelection == 2 then
    --Delete Everything
    for e in pairs(EntitySystem.query("simpleObject")) do
      EntitySystem.delete(e)
    end
    for e in pairs(EntitySystem.query("physical")) do
      EntitySystem.delete(e)
    end
    for e in pairs(EntitySystem.query("camFollows")) do
      EntitySystem.delete(e)
    end
    for e in pairs(EntitySystem.query("texturedObject")) do
      EntitySystem.delete(e)
    end
    for e in pairs(EntitySystem.query("animatedObject")) do
      EntitySystem.delete(e)
    end
    for e in pairs(EntitySystem.query("soundEffect")) do
      EntitySystem.delete(e)
    end
    for e in pairs(EntitySystem.query("hud")) do
      EntitySystem.delete(e)
    end
    
    --Go to the Main Menu
    Gamestate.switch(mainMenu)
  end
  
  
end
function pauseMenu:keyreleased(k)
end
function pauseMenu:mousepressed(x,y,b)
end
function pauseMenu:mousereleased(x,y,b)
end
